//加载，当加载完了之后运行调用函数
window.addEventListener("load", eventWindowLoaded, false);

function eventWindowLoaded(){

	var theCanvas = document.getElementById("canvas");

	var context = theCanvas.getContext('2d');

	var alpha = 1;

	var fadeIn = 0;

	var text = "吼哈！";

	var img = new Image();

	img.src = "../image/jph.jpg";

	function drawScreen(){
		// 背景
		context.globalAlpha = 1;
		context.fillStyle = "#000000";
		context.fillRect(0, 0, 400, 711);
		// 图片
		context.globalAlpha = alpha;
		context.drawImage(img, 0, 0, 400, 711);

		if(fadeIn){
			alpha += 0.01;
			if(alpha >= 1){
				alpha = 1;
				fadeIn = false;
			}
		}else{
			alpha -= 0.01;
			if(alpha < 0){
				alpha = 0;
				fadeIn = true;
			}
		}
		// 文本
		context.font = "72px Sans-Serif";
		context.textBaseLine = "top";

		context.globalAlpha = alpha;
		context.fillStyle = "#ffffff";
		context.fillText(text, 50, 200);
	}

	function gameLoop(){
		window.setTimeout(gameLoop, 20);
		drawScreen();
	}

	gameLoop();
}

	
